testsuite: add a test for non-square symbolic icons
authorCosimo Cecchi <cosimoc@gnome.org>
Thu, 11 Jun 2015 03:52:14 +0000 (20:52 -0700)
committerCosimo Cecchi <cosimoc@gnome.org>
Fri, 12 Jun 2015 15:55:23 +0000 (08:55 -0700)
To verify the previous fix.

https://bugzilla.gnome.org/show_bug.cgi?id=750605

testsuite/gtk/Makefile.am
testsuite/gtk/icons/scalable/nonsquare-symbolic.svg [new file with mode: 0644]
testsuite/gtk/icontheme.c

index ea828ce5ac959bcb0ffe6c02772db527fc724fee..9a3809e4f48ea6a7cbaf4f1f4ff641786fe9ec4f 100644 (file)
@@ -153,6 +153,7 @@ test_icontheme =                                    \
        icons/scalable/everything-justsymbolic-symbolic.svg     \
        icons/scalable/everything.svg                   \
        icons/scalable/everything-symbolic.svg          \
+       icons/scalable/nonsquare-symbolic.svg           \
        icons/15/size-test.png                          \
        icons/16-22/size-test.png                       \
        icons/25+/size-test.svg                         \
diff --git a/testsuite/gtk/icons/scalable/nonsquare-symbolic.svg b/testsuite/gtk/icons/scalable/nonsquare-symbolic.svg
new file mode 100644 (file)
index 0000000..2df92d0
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>\r
+<!-- Generator: Adobe Illustrator 17.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->\r
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\r
+<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"\r
+        width="12px" height="18px" viewBox="-0.5 0.5 12 18" enable-background="new -0.5 0.5 12 18" xml:space="preserve">\r
+<g id="Captions">\r
+</g>\r
+<path d="M9.5,11.5h-7l-3-3v3v5c0,1.105,0.895,2,2,2h8c1.105,0,2-0.895,2-2v-3C11.5,12.395,10.605,11.5,9.5,11.5z M9.5,16.5h-8v-1h8\r
+       V16.5z M9.5,14.5h-8v-1h8V14.5z"/>\r
+<path d="M9.5,0.5h-8c-1.105,0-2,0.895-2,2v3c0,1.105,0.895,2,2,2h7l3,3v-3v-5C11.5,1.395,10.605,0.5,9.5,0.5z M9.5,5.5h-8v-1h8V5.5z\r
+        M9.5,3.5h-8v-1h8V3.5z"/>\r
+</svg>\r
index de895c29d3831f047d71260a212458f355733863..7fcb1609f150a550ebafc19a7271a028063243a6 100644 (file)
@@ -698,6 +698,60 @@ test_inherit (void)
                       "/icons2/scalable/one-two-symbolic-rtl.svg");
 }
 
+static void
+test_nonsquare_symbolic (void)
+{
+  gint width, height;
+  GtkIconTheme *icon_theme;
+  GtkIconInfo *info;
+  GFile *file;
+  GIcon *icon;
+  GdkRGBA black = { 0.0, 0.0, 0.0, 1.0 };
+  gboolean was_symbolic = FALSE;
+  GError *error = NULL;
+  gchar *path = g_build_filename (g_test_get_dir (G_TEST_DIST),
+                                 "icons",
+                                 "scalable",
+                                 "nonsquare-symbolic.svg",
+                                 NULL);
+
+  /* load the original image for reference */
+  GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (path, &error);
+  g_assert_no_error (error);
+  g_assert_nonnull (pixbuf);
+
+  width = gdk_pixbuf_get_width (pixbuf);
+  height = gdk_pixbuf_get_height (pixbuf);
+  g_assert_cmpint (width, !=, height);
+
+  /* now load it through GtkIconTheme */
+  icon_theme = gtk_icon_theme_get_default ();
+  file = g_file_new_for_path (path);
+  icon = g_file_icon_new (file);
+  info = gtk_icon_theme_lookup_by_gicon_for_scale (icon_theme, icon,
+                                                  height, 1, 0);
+  g_assert_nonnull (info);
+
+  g_object_unref (pixbuf);
+  pixbuf = gtk_icon_info_load_symbolic (info, &black, NULL, NULL, NULL,
+                                       &was_symbolic, &error);
+
+  /* we are loaded successfully */
+  g_assert_no_error (error);
+  g_assert_nonnull (pixbuf);
+  g_assert_true (was_symbolic);
+
+  /* the original dimensions have been preserved */
+  g_assert_cmpint (gdk_pixbuf_get_width (pixbuf), ==, width);
+  g_assert_cmpint (gdk_pixbuf_get_height (pixbuf), ==, height);
+
+  g_free (path);
+  g_object_unref (pixbuf);
+  g_object_unref (file);
+  g_object_unref (icon);
+  g_object_unref (info);
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -716,6 +770,7 @@ main (int argc, char *argv[])
   g_test_add_func ("/icontheme/list", test_list);
   g_test_add_func ("/icontheme/async", test_async);
   g_test_add_func ("/icontheme/inherit", test_inherit);
+  g_test_add_func ("/icontheme/nonsquare-symbolic", test_nonsquare_symbolic);
 
   return g_test_run();
 }